import { toText } from '@/utils/file';
import { programData } from '@/store/modules/program/utils';
import { message } from '../message/bus';
import { notify } from '../notify/bus';

export const drop = async (e: DragEvent) => {
  e.preventDefault();
  const files = e.dataTransfer?.files;
  if (files?.length === 1) {
    const text = await toText(files[0]);
    try {
      notify({
        msg: '导入文件将会覆盖之前的记录',
        onConfirm() {
          const list = JSON.parse(text);
          const data = programData();
          data.list = list;
        },
        title: '警告',
      });
    } catch (error) {
      message('文件解析错误,请确保拖入有效的文件');
    }
  } else {
    message('暂时不支持处理多个文件');
  }
};
export const cancleEvent = (e: Event) => {
  e.preventDefault();
};
